package com.jhws.business.owner.bo;

import com.jhws.business.owner.service.ITblOwnerDimService;
import com.jhws.core.dataUpdate.bo.DataUpdateObject;
import com.jhws.core.dataUpdate.bo.IDataUpdateModule;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import com.jhws.core.exception.BizException;
import com.jhws.util.LogHelper;
import com.jhws.util.StringUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;

@Component
public class OwnerDataUpdate implements IDataUpdateModule {
    static public final String APPLY_OWNER = "owner_property";
    private String [] name = {APPLY_OWNER};
    @Resource
    private ITblOwnerDimService ownerDimService;
    @Resource
    private DataUpdateService dataUpdateService;


    @Override
    public String [] getModuleName() {
        return name;
    }

    @Override
    public DataUpdateObject getUserModuleData(String username,String ownerCode, Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {

        if (timeStamp == null || StringUtils.isEmpty(ownerCode)) {
            LogHelper.e("参数错误");
            return null;
        }

        TblOwnerDimBo owner = ownerDimService.findTblOwnerDimById(ownerCode);
        String where = "where comm_code = '" + owner.getCommCode() + "' and apply_type='" + OwnerConstant.OWNER_TYPE_APPLYING + "'";
        where += " and lastModifyTimeStamp > '" + timeStamp + "'";
        DataUpdateObject dataUpdateObject = new DataUpdateObject();
        dataUpdateObject.setSize(ownerDimService.findOwnerCountByWhere(where));
        return dataUpdateObject;
    }

    @Override
    public DataUpdateObject getLabelModuleData(String label, Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {
        return null;
    }

    @Override
    @PostConstruct
    public void registerModule() {
        dataUpdateService.registerModule(this);
    }
}
